import pytest
import requests
from api.ihrmEmpManageApi import EmpManageApi
from common.assertTools import common_assert
from common.db_tools import DBTools
from common.getHeader import get_header
from common.read_jsondata import read_json_file
from config import TEL, BASE_PATH

class TestAddEmp(object):
    def setup_class(self):
        # 创建实例
        self.emp = EmpManageApi()
        # 准备请求头
        self.req_header = get_header()
    def setup(self):#在每个普通方法执行前,自动调用(先删除数据库手机号)
        DBTools.db_iud(f"delete from bs_user where mobile='{TEL}';")
    def teardown(self):#测试结束后,自动调用删除这个手机号
        DBTools.db_iud(f"delete from bs_user where mobile='{TEL}';")

    # 拼接json文件的绝对路径,读取,获得[(),()]格式数据
    file_name = BASE_PATH + "/data/addEmpData.json"
    res = read_json_file(file_name)

    @pytest.mark.parametrize("desc,json_data,status_code,success,code,message",res)
    # 添加成功
    def test1_add_success(self,desc,json_data,status_code,success,code,message):
        # 调用添加员工
        resp = self.emp.add_emp(self.req_header, json_data)
        print(desc,"：", resp.json())
        # 断言
        common_assert(resp, status_code,success,code,message)


